<?php
/**
 * Created by PhpStorm.
 * User: Z
 * Date: 2017/3/21
 * Time: 13:56
 */

namespace Home\Server;

/**
 * Class UserService
 * @package Home\Server
 *
 * Author: 黄盖
 * Date: 2017-3-21 14:24
 * Info: 创建一个类
 */
class UserService
{
    function __construct()
    {

    }

    /**
     * Function setUserInfo
     * @param int $UID
     * @param array $UpdateData
     *
     * Author: 黄盖
     * Date: 2017-3-21 14:55
     * Info: 设置用户信息
     */
    public function setUserInfo( $UID = 0, $UpdateData = Array() )
    {
        $UID = intval( $UID );

        if( $UID <= 0 || empty( $UpdateData ) )
        {
            return False;
        }

        return M("tp_user") ->where("`f_user_id` = '{$UID}'") ->data( $UpdateData ) ->save();
    }

    /**
     * Function verify_superPwd
     * @param $UID          用户DID
     * @param $superPwd     用户超级密码
     * @return bool
     *
     * Author: 黄盖
     * Date: 2017-3-21 15:45
     * Info:查询该用户超级密码是否正确
     */
    public function verify_superPwd( $UID, $superPwd )
    {
        $userData = M("tp_user") ->field('`f_user_id`') ->where("`f_user_id` = '{$UID}' AND `f_super_password` = '{$superPwd}'") ->find();

        if( is_array( $userData ) && count( $userData ) > 0 )
        {
            return True;
        }

        return False;
    }

    /**
     * Function verify_professional
     * @param $UID
     *
     * Author: 黄盖
     * Date: 2017-4-6 14:05
     * Info: 验证是否是专业版
     */
    public function verify_professional( $UID )
    {
        $userData = M("tp_user") ->field('`f_user_id`') ->where("`f_user_id` = '{$UID}' AND `f_professional` = 1") ->find();

        if( is_array( $userData ) && count( $userData ) > 0 )
        {
            return True;
        }

        return False;
    }

    /**
     * Function getPlatform
     * @param $bmxSource    平台
     * @param bool $isAPP
     *
     * Author: 黄盖
     * Date: 2017-4-11 11:45
     * Info: 出库平台  0 未知  1 IOS  2 Andoird  3 PC  5 微信
     */
    public function getPlatform( $bmxSource, $isAPP = False )
    {
        //API接口
        if( $isAPP )
        {
            if( $bmxSource == 'ios' )
            {
                return 1;
            }
            else if( $bmxSource == 'android' )
            {
                return 2;
            }
            else
            {
                return 0;
            }
        }
        else
        {
            return 3;
        }
    }
}